home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / stdlib / stdlib.h < prev    next >
C/C++ Source or Header  |  1992-11-16  |  9KB  |  272 lines

  1. /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    ANSI Standard: 4.10 GENERAL UTILITIES    <stdlib.h>
  21.  */
  22.  
  23. #ifndef    _STDLIB_H
  24.  
  25. #define    _STDLIB_H    1
  26. #include <features.h>
  27.  
  28. /* Get size_t, wchar_t and NULL from <stddef.h>.  */
  29. #define    __need_size_t
  30. #define    __need_wchar_t
  31. #define    __need_NULL
  32. #include <stddef.h>
  33.  
  34. #define    __need_Emath
  35. #include <errno.h>
  36.  
  37. __BEGIN_DECLS
  38.  
  39. /* Returned by `div'.  */
  40. typedef struct
  41.   {
  42.     int quot;            /* Quotient.  */
  43.     int rem;            /* Remainder.  */
  44.   } div_t;
  45.  
  46. /* Returned by `ldiv'.  */
  47. typedef struct
  48.   {
  49.     long int quot;        /* Quotient.  */
  50.     long int rem;        /* Remainder.  */
  51.   } ldiv_t;
  52.  
  53.  
  54. /* The largest number rand will return (same as INT_MAX).  */
  55. #define    RAND_MAX    2147483647
  56.  
  57.  
  58. /* We define these the same for all machines.
  59.    Changes from this to the outside world should be done in `_exit'.  */
  60. #define    EXIT_FAILURE    1    /* Failing exit status.  */
  61. #define    EXIT_SUCCESS    0    /* Successful exit status.  */
  62.  
  63.  
  64. /* Maximum length of a multibyte character in the current locale.
  65.    This is just one until the fancy locale support is finished.  */
  66. #define    MB_CUR_MAX    1
  67.  
  68.  
  69. /* Convert a string to a floating-point number.  */
  70. extern double atof __P ((__const char *__nptr));
  71. /* Convert a string to an integer.  */
  72. extern int atoi __P ((__const char *__nptr));
  73. /* Convert a string to a long integer.  */
  74. extern long int atol __P ((__const char *__nptr));
  75.  
  76. /* Convert a string to a floating-point number.  */
  77. extern double strtod __P ((__const char *__nptr, char **__endptr));
  78. /* Convert a string to a long integer.  */
  79. extern long int strtol __P ((__const char *__nptr, char **__endptr,
  80.                  int __base));
  81. /* Convert a string to an unsigned long integer.  */
  82. extern unsigned long int strtoul __P ((__const char *__nptr,
  83.                        char **__endptr, int __base));
  84.  
  85. #ifdef    __OPTIMIZE__
  86. #define    atof(nptr)    strtod((nptr), (char **) NULL)
  87. #define    atoi(nptr)    ((int) atol(nptr))
  88. #define    atol(nptr)    strtol((nptr), (char **) NULL, 10)
  89. #endif /* Optimizing.  */
  90.  
  91.  
  92. /* Return a random integer between 0 and RAND_MAX inclusive.  */
  93. extern int rand __P ((void));
  94. /* Seed the random number generator with the given number.  */
  95. extern void srand __P ((unsigned int __seed));
  96.  
  97. /* These are the functions that actually do things.  The `random', `srandom',
  98.    `initstate' and `setstate' functions are those from BSD Unices.
  99.    The `rand' and `srand' functions are required by the ANSI standard.
  100.    We provide both interfaces to the same random number generator.  */
  101. /* Return a random long integer between 0 and RAND_MAX inclusive.  */
  102. extern long int __random __P ((void));
  103. /* Seed the random number generator with the given number.  */
  104. extern void __srandom __P ((unsigned int __seed));
  105.  
  106. /* Initialize the random number generator to use state buffer STATEBUF,
  107.    of length STATELEN, and seed it with SEED.  Optimal lengths are 8, 16,
  108.    32, 64, 128 and 256, the bigger the better; values less than 8 will
  109.    cause an error and values greater than 256 will be rounded down.  */
  110. extern __ptr_t __initstate __P ((unsigned int __seed, __ptr_t __statebuf,
  111.                  size_t __statelen));
  112. /* Switch the random number generator to state buffer STATEBUF,
  113.    which should have been previously initialized by `initstate'.  */
  114. extern __ptr_t __setstate __P ((__ptr_t __statebuf));
  115.  
  116. #ifdef    __USE_BSD
  117. extern long int random __P ((void));
  118. extern void srandom __P ((unsigned int __seed));
  119. extern __ptr_t initstate __P ((unsigned int __seed, __ptr_t __statebuf,
  120.                    size_t __statelen));
  121. extern __ptr_t setstate __P ((__ptr_t __statebuf));
  122.  
  123. #ifdef    __OPTIMIZE__
  124. #define    random()        __random()
  125. #define    srandom(seed)        __srandom(seed)
  126. #define    initstate(s, b, n)    __initstate((s), (b), (n))
  127. #define    setstate(state)        __setstate(state)
  128. #endif /* Optimizing.  */
  129. #endif /* Use BSD.  */
  130.  
  131. #ifdef    __OPTIMIZE__
  132. #define    rand()        ((int) __random())
  133. #define    srand(seed)    __srandom(seed)
  134. #endif /* Optimizing.  */
  135.  
  136.  
  137. /* Allocate SIZE bytes of memory.  */
  138. extern __ptr_t malloc __P ((size_t __size));
  139. /* Re-allocate the previously allocated block
  140.    in __ptr_t, making the new block SIZE bytes long.  */
  141. extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size));
  142. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
  143. extern __ptr_t calloc __P ((size_t __nmemb, size_t __size));
  144. /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
  145. extern void free __P ((__ptr_t __ptr));
  146.  
  147. #ifdef    __USE_MISC
  148. /* Free a block.  An alias for `free'.    (Sun Unices).  */
  149. extern void cfree __P ((__ptr_t __ptr));
  150.  
  151. #ifdef    __OPTIMIZE__
  152. #define    cfree(ptr)    free(ptr)
  153. #endif /* Optimizing.  */
  154. #endif /* Use misc.  */
  155.  
  156. #if defined(__USE_GNU) || defined(__USE_BSD) || defined(__USE_MISC)
  157. #include <alloca.h>
  158. #endif /* Use GNU, BSD, or misc.  */
  159.  
  160. #ifdef    __USE_BSD
  161. /* Allocate SIZE bytes on a page boundary.  The storage cannot be freed.  */
  162. extern __ptr_t valloc __P ((size_t __size));
  163. #endif
  164.  
  165.  
  166. /* Abort execution and generate a core-dump.  */
  167. extern __NORETURN void abort __P ((void));
  168.  
  169.  
  170. /* Register a function to be called when `exit' is called.  */
  171. extern int atexit __P ((void (*__func) (void)));
  172.  
  173. #ifdef    __USE_MISC
  174. /* Register a function to be called with the status
  175.    given to `exit' and the given argument.  */
  176. extern int on_exit __P ((void (*__func) (int __status, __ptr_t __arg),
  177.              __ptr_t __arg));
  178. #endif
  179.  
  180. /* Call all functions registered with `atexit' and `on_exit',
  181.    in the reverse of the order in which they were registered
  182.    perform stdio cleanup, and terminate program execution with STATUS.  */
  183. extern __NORETURN void exit __P ((int __status));
  184.  
  185.  
  186. /* Return the value of envariable NAME, or NULL if it doesn't exist.  */
  187. extern char *getenv __P ((__const char *__name));
  188.  
  189. #ifdef    __USE_SVID
  190. /* The SVID says this is in <stdio.h>, but this seems a better place.    */
  191. /* Put STRING, which is of the form "NAME=VALUE", in the environment.
  192.    If there is no `=', remove NAME from the environment.  */
  193. extern int putenv __P ((__const char *__string));
  194. #endif
  195.  
  196. #ifdef    __USE_BSD
  197. /* Set NAME to VALUE in the environment.
  198.    If REPLACE is nonzero, overwrite an existing value.  */
  199. extern int setenv __P ((__const char *__name, __const char *__value,
  200.             int __replace));
  201. #endif
  202.  
  203. /* Execute the given line as a shell command.  */
  204. extern int system __P ((__const char *__command));
  205.  
  206.  
  207. /* Shorthand for type of comparison functions.  */
  208. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  209.  
  210. #ifdef    __USE_GNU
  211. typedef __compar_fn_t comparison_fn_t;
  212. #endif
  213.  
  214. /* Do a binary search for KEY in BASE, which consists of NMEMB elements
  215.    of SIZE bytes each, using COMPAR to perform the comparisons.  */
  216. extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
  217.                  size_t __nmemb, size_t __size,
  218.                  __compar_fn_t __compar));
  219.  
  220. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  221.    using COMPAR to perform the comparisons.  */
  222. extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
  223.             __compar_fn_t __compar));
  224.  
  225.  
  226. #ifndef    __CONSTVALUE
  227. #ifdef    __GNUC__
  228. /* The `const' keyword tells GCC that a function's return value is
  229.    based solely on its arguments, and there are no side-effects.  */
  230. #define    __CONSTVALUE    __const
  231. #else
  232. #define    __CONSTVALUE
  233. #endif /* GCC.  */
  234. #endif /* __CONSTVALUE not defined.  */
  235.  
  236. /* Return the absolute value of X.  */
  237. extern __CONSTVALUE int abs __P ((int __x));
  238. extern __CONSTVALUE long int labs __P ((long int __x));
  239.  
  240.  
  241. /* Return the `div_t' or `ldiv_t' representation
  242.    of the value of NUMER over DENOM. */
  243. /* GCC may have built-ins for these someday.  */
  244. extern __CONSTVALUE div_t div __P ((int __numer, int __denom));
  245. extern __CONSTVALUE ldiv_t ldiv __P ((long int __numer, long int __denom));
  246.  
  247.  
  248. /* Return the length of the multibyte character
  249.    in S, which is no longer than N.  */
  250. extern int mblen __P ((__const char *__s, size_t __n));
  251. /* Return the length of the given multibyte character,
  252.    putting its `wchar_t' representation in *PWC.  */
  253. extern int mbtowc __P ((wchar_t * __pwc, __const char *__s, size_t __n));
  254. /* Put the multibyte character represented
  255.    by WCHAR in S, returning its length.  */
  256. extern int wctomb __P ((char *__s, wchar_t __wchar));
  257.  
  258. #ifdef    __OPTIMIZE__
  259. #define    mblen(s, n)    mbtowc((wchar_t *) NULL, (s), (n))
  260. #endif /* Optimizing.  */
  261.  
  262.  
  263. /* Convert a multibyte string to a wide char string.  */
  264. extern size_t mbstowcs __P ((wchar_t * __pwcs, __const char *__s, size_t __n));
  265. /* Convert a wide char string to multibyte string.  */
  266. extern size_t wcstombs __P ((char *__s, __const wchar_t * __pwcs, size_t __n));
  267.  
  268.  
  269. __END_DECLS
  270.  
  271. #endif /* stdlib.h  */
  272.